<!DOCTYPE HTML>
<html lang="cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <%include("/common/header.html",{title:''}){}%>
    <title>施工团队</title>
    <style>
    </style>
</head>
<script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=IENn7ABARjQIkTeAKyh80VTkg2jYXf3K"></script>
<body>

<div class="x-nav" style="margin: 20px auto auto 15px;">
      <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
       <a href="javascript:;">首页</a><span lay-separator="">/</span>
        <a href="javascript:;">用户列表</a><span lay-separator="">/</span>
      </span>
    <a class="layui-btn layui-btn-primary layui-btn-small" style="margin: -5px 14px 0px 0px;float:right;"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-3"></i>
    </a>
</div>

<div class="x-body" style="margin: 20px auto auto 15px;">
    <div class="layui-row" >
        <div class="layui-input-inline">
            <input type="text" id="search_term"  placeholder="请输入内容" class="layui-input" >
        </div>
        <div class="layui-input-inline">
            <button  class="layui-btn layui-btn-checked" lay-submit="" lay-filter="sreach" id="searchBtn" > <i class="layui-icon layui-icon-search"></i>查询</button>
        </div>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-card">
        <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
        <script type="text/html" id="toolbarDemo">

        </script>
        <script type="text/html" id="table-useradmin-webuser">
            <a class="layui-btn  layui-btn-xs" lay-event="belongTo"><i class="layui-icon layui-icon-form"></i>所属代理商</a>
            <a class="layui-btn  layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-form"></i>查看</a>
            <a class="layui-btn  layui-btn-xs" lay-event="listen"><i class="layui-icon layui-icon-form"></i>监测数据</a>
        </script>
        <!--查看设备-->
        <script type="text/html" id="table-useradmin-webuser-b">
            <a class="layui-btn  layui-btn-xs" lay-event="shebei"><i class="layui-icon layui-icon-form"></i>查看</a>
        </script>
        <!--开通功能-->
        <script type="text/html" id="selectRepairItemName">
            <select name="RepairItemName" lay-filter="RepairItemName" data-value="">
                <option value="2">大屏展示</option>
            </select>
        </script>

        <!--激活状态-->
        <script type="text/html" id="isCross-sysUser">
            {{#  if(d.isCross === 1){ }}
            <div style="color: #0e94ea">审核中</div>
            {{#  } }}
            {{#  if(d.isCross === 0){ }}
            <div style="color: cadetblue">已激活</div>
            {{#  } }}
            {{#  if(d.isCross ===2){ }}
            <div style="color: red">未通过</div>
            {{#  } }}
        </script>
    </div>
</div>

<!--弹出开设账号-->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin"
     id="layuiadmin-form-useradmin"
     style="padding: 15px;display: none">
    <form class="layui-form" action="" lay-filter="component-form-element" id="myform">
        <input type="hidden" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label">*账号</label>
            <div class="layui-input-inline">
                <input type="text" name="phone" lay-verify="required" placeholder="请输入账号" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*密码</label>
            <div class="layui-input-inline">
                <input type="text" name="passWord" lay-verify="required" placeholder="请输入密码" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*名称</label>
            <div class="layui-input-inline">
                <input type="text" name="name" lay-verify="required" placeholder="请输入用户名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*地址</label>
            <div class="layui-input-inline">
                <input type="text" name="address" lay-verify="required" placeholder="请输入用户地址" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*个人/企业</label>
            <div class="layui-input-inline">
                <input type="radio" name="isPerson" lay-verify="required" class="layui-input" title="个人" value="0">
                <input type="radio" name="isPerson" lay-verify="required" class="layui-input" title="企业" value="1">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*身份证号/社会信用代码</label>
            <div class="layui-input-inline">
                <input type="text" name="idCard" lay-verify="required" placeholder="请输入证件号" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">*联系方式</label>
            <div class="layui-input-inline">
                <input type="text" name="mobile" lay-verify="required" placeholder="请输入联系方式" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*开户行名称</label>
            <div class="layui-input-inline">
                <input type="text" name="bankName" lay-verify="required" placeholder="请输入开户行名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*银行卡号</label>
            <div class="layui-input-inline">
                <input type="text" name="bankNum" lay-verify="required" placeholder="请输入银行卡号并核实" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="text" name="email" placeholder="请输入邮箱" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">固定电话</label>
            <div class="layui-input-inline">
                <input type="text" name="telePhone" placeholder="请输入固定电话(可选填)" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">立即提交</button>
            </div>
        </div>
    </form>
</div>

<!--查看详情-->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin-aa"
     id="layuiadmin-form-useradmin-aa"
     style="padding: 15px;display: none">
    <form class="layui-form" action="" lay-filter="component-form-element-aa" id="myformView">
        <input type="hidden" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label">*用户账号</label>
            <div class="layui-input-inline">
                <input type="text" name="phone" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*用户密码</label>
            <div class="layui-input-inline">
                <input type="text" name="passWord" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*用户名称</label>
            <div class="layui-input-inline">
                <input type="text" name="name" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*地址</label>
            <div class="layui-input-inline">
                <input type="text" name="address" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>
        <!--????-->
        <div class="layui-form-item">
            <label class="layui-form-label">*个人/企业</label>
            <div class="layui-input-inline">
                <input type="text" name="isPerson" id="isPerson" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">*身份证号/社会信用代码</label>
            <div class="layui-input-inline">
                <input type="text" name="idCard" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">*健康分值</label>
            <div class="layui-input-inline">
                <input type="text" name="healthScore" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*联系方式</label>
            <div class="layui-input-inline">
                <input type="text" name="mobile" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*开户行名称</label>
            <div class="layui-input-inline">
                <input type="text" name="bankName" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*银行卡号</label>
            <div class="layui-input-inline">
                <input type="text" name="bankNum" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">固定电话</label>
            <div class="layui-input-inline">
                <input type="text" name="telePhone" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
                <input type="text" name="email" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*注册时间</label>
            <div class="layui-input-inline">
                <input type="text" name="createDate" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">*到期时间</label>
            <div class="layui-input-inline">
                <input type="text" name="endTime" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>
    </form>
</div>

<!--所属代理商信息-->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin-d"
     id="layuiadmin-form-useradmin-d"
     style="padding: 15px;display: none">
    <form class="layui-form" action="" lay-filter="component-form-element-d">
        <input type="hidden" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label">名称:</label>
            <div class="layui-input-inline">
                <input type="text" name="name" id="aname" readonly placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电话:</label>
            <div class="layui-input-inline">
                <input type="text" name="phone" id="aphone" readonly placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">地址:</label>
            <div class="layui-input-inline">
                <input type="text" name="address" id="a_address" readonly placeholder="" class="layui-input">
            </div>
        </div>
    </form>
</div>

<!--弹出设备-->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin-b"
     id="layuiadmin-form-useradmin-b"
     style="padding: 15px;display: none">
    <form class="layui-form" action="" lay-filter="component-form-element-c" id="myform2">
        <div class="layui-form-item">
            <h3 class="layui-form-label">商品信息</h3>
            <table class="layui-table" lay-size="lg">
                <thead>
                <tr>
                    <th width="200">名称</th>
                    <th width="40">单价</th>
                    <th width="30">数量</th>
                </tr>
                </thead>
                <tbody id="yigougoods">

                </tbody>
            </table>
        </div>
    </form>
</div>



<!--弹出附加功能-->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin-e"
     id="layuiadmin-form-useradmin-e"
     style="padding: 15px;display: none">
    <form class="layui-form" action="" lay-filter="component-form-element-e" id="myform1">
        <input type="hidden" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label">全局展示:</label>
            <div class="layui-input-inline">
                <input type="checkbox" name="phone" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">人工智能:</label>
            <div class="layui-input-inline">
                <input type="checkbox" name="passWord" lay-verify="required" readonly="readonly" placeholder="" class="layui-input">
            </div>
        </div>

<!--        <div class="layui-form-item">-->
<!--            <div class="layui-input-block" style="margin-top: 60px">-->
<!--                <button class="layui-btn" lay-submit="" lay-filter="component-form-element-e">立即提交</button>-->
<!--            </div>-->
<!--        </div>-->
    </form>
</div>
<%include("/common/foot.html"){}%>
<script id="edgoods" type="text/html">
    {{#  layui.each(d.list, function(index, item){ }}
    <tr>
        <td>{{item.goods.goodName}}</td>
        <td>{{item.goods.price}}</td>
        <td>{{item.numbers}}</td>
    </tr>
    {{#  }); }}
</script>
<script>
    layui.use(['index', 'table', 'jquery','form', 'laytpl','laydate', 'layedit', 'AjaxCommon', 'AliangLayui', 'AliangCommon'], function () {
        var $ = layui.$;
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        var AjaxCommon = layui.AjaxCommon;
        var AliangLayui = layui.AliangLayui;
        var laytpl=layui.laytpl;

        var title = "开设账户";
        var findAll_url="saleMan/sys/findAll.jhtml";
        var saveUser_url="saleMan/sys/saveUser.jhtml"
        var delete_url="system/openAccount/deleteById.jhtml";
        var index;//定义建立富文本编辑器全局变量
        var layedit;//定义富文本编辑器layedit全局变量
        var cols = [ //表头
            //  {field:'id',sort:'true',title:'序号',align:'center'},
            {field:'name',title:'用户名称',align:'center'},
            {field: 'createDate', title: '注册时间',align:'center',templet: "<div>{{layui.util.toDateString(d.createDate, 'yyyy-MM-dd ')}}</div>"},
            {field:'address',title:'地址',align:'center'},
            {title: '设备', sort:'true',width: 100, toolbar: '#table-useradmin-webuser-b',align:'center'},
            {field:'healthScore',title:'健康分值',align:'center'},
            {field: 'mobile',  title: '联系方式',align:'center'},
            {field: 'isCross',title:'激活状态',align: 'center',toolbar: '#isCross-sysUser'},
            {title: '操作', fixed: 'right', width: 300, toolbar: '#table-useradmin-webuser',align:'center'}
        ];
        AliangLayui.createTable(
            "#LAY-user-manage",
            "listReload",
            "#toolbarDemo",
            title,
            findAll_url,
            true,
            [10, 15, 20, 25],
            ['filter', 'print', 'exports'],
            cols,
            null
        );

        // function ty(data){
        //     if (data==1){
        //         return "鸡舍"
        //     }else if(data==2){
        //         return "牛舍"
        //     }else if(data==3){
        //         return "猪舍"
        //     }else if(data==4){
        //         return "兔舍"
        //     }else if(data==5){
        //         return "鸭舍"
        //     }
        // }
        var keyWord;
        $('#searchBtn').on('click', function () {
            keyWord = $('#search_term').val();
            if (""==keyWord||undefined==keyWord){
                window.location.reload();
            }else{
                table.reload('listReload', {
                    url: findAll_url,
                    where: {
                        keyWord: keyWord
                    },
                    page: {
                        curr: 1//重新从第 1 页开始
                    }
                });
            }
        });
        //////////////////////////////////////以上是修改每个页面修改的地方
        //弹出修改页面调用初始化数据方法
        var findRoleName_url="role/json_role.jhtml";
        var title1="开设账号";
        var size = ['100%', '100%'];
        function initUpdate(data) {
            layer.open({
                type: 1,
                title: title1,
                area:size,
                content: $('#layuiadmin-form-useradmin'),
                cancel: function (index, layero) {//取消事件
                    location.replace(location.href);　//layer.open关闭刷新
                },
                success: function (layero, index) {
                    layer.iframeAuto(index);
                }
            });
            //富文本表单验证
            form.verify({
                introduce: function (value) {
                    var val = layedit.getText(index);
                    if (val.length < 6) {
                        return '内容至少6个字符'
                    }
                }
            });
            if (data==null||data==0){
                $('#myform')[0].reset();
                return;
            }else{
                layui.form.val('component-form-element',loadData(data))
            }
        }
        //弹出设备
        function openSheBei(data) {
            layer.open({
                type: 1,
                title: "设备",
                area: ['100%', '100%'],
                content: $('#layuiadmin-form-useradmin-b')
            });
            var findOrderInfo="view/findOrderInfo.jhtml"
            $.ajax({
                url:findOrderInfo,
                type: "POST",
                data: {
                    "sid": data
                },
                dataType:'json',
                success: function (ret) {
                    console.log(JSON.stringify(ret))
                    var data=ret.data;
                    var laytpl = layui.laytpl;
                    var ret2 = { //数据
                        "list": data[0].detailsSet
                    };
                    laytpl($("#edgoods").html()).render(ret2, function (html) {
                        $("#yigougoods").html(html);
                    });
                }
            })
        }
        //附加功能选项
        function openZengZhi(data) {
            layer.open({
                type: 1,
                title: "增值功能",
                area: ['100%', '100%'],
                content: $('#layuiadmin-form-useradmin-')
            });
        }
        //弹出查看页面调用初始化数据方法
        var viewTitle="查看详情"
        function initUpdate1(data) {
            layer.open({
                type: 1,
                title: viewTitle,
                area: ['100%', '100%'],
                content: $('#layuiadmin-form-useradmin-aa')
            });
            //给表单赋值
            layui.form.val("component-form-element-aa", loadData(data));
        }
        function loadData(data){
            var ret = {
                "id": data.id,
                "phone": data.phone,
                "passWord": data.passWord,
                "name": data.name,
                "idCard":data.idCard,
                "mobile":data.mobile,
                "bankName": data.bankName,
                "bankNum":data.bankNum,
                "createDate":data.createDate,
                "endTime":data.endTime,
                "telePhone":data.telePhone,
                "healthScore":data.healthScore,
                "email":data.email,
                "idCard":data.idCard,
                "address":data.address,
                "placeType":data.placeType
            };
            //isPerson
            if (data.isPerson==0){
                $("#isPerson").val("个人")
            }else{
                $("#isPerson").val("企业")
            }

            // for (let i = 0; i < dataStr(data.placeType).length; i++) {
            //     var place=dataStr(data.placeType)[i];
            //     $("input:checkbox[value='"+place+"']").attr("checked","checked");
            // }
            form.render();
            return ret;
        }

        //得出的字符串变成整型数组
        // function dataStr(data){
        //     var newStr=data.split(",")
        //     var newArray=[];
        //     newArray=newStr.map(function(data){
        //         return +data;
        //     })
        //     return newArray;
        // }

        function initUpdateBelongTo(data){
            // alert(data)
            var title1="代理商信息";
            layer.open({
                type: 1,
                title: title1,
                area:['100%', '100%'],
                content: $('#layuiadmin-form-useradmin-d'),
                btn: ['关闭'], //可以无限个按钮
                cancel: function (index, layero) {//取消事件
                    location.replace(location.href);　//layer.open关闭刷新
                },
                success: function (layero, index) {
                    layer.iframeAuto(index);
                }
            });

            var findByAgent_url="saleMan/sys/findByAgent.jhtml";
            $.ajax({
                url:findByAgent_url,
                type: "POST",
                data: {
                    "aid": data
                },
                dataType:'json',
                success: function (ret) {
                    // alert(JSON.stringify(ret))
                    // console.log(JSON.stringify(ret.data))
                    layui.form.val("component-form-element-d", loadDataBe(ret.data));
                }
            })
        }


        function loadDataBe(data){
            $("#aname").val(data.name)
            $("#aphone").val(data.phone)
            $("#a_address").val(data.address)
            form.render();
        }


        $.fn.ghostsf_serialize = function () {
            var a = this.serializeArray();
            var $radio = $('input[type=checkbox]', this);
            var temp = {};
            $.each($radio, function () {
                if (!temp.hasOwnProperty(this.name)) {
                    if ($("input[name='" + this.name + "']:checked").length == 0) {
                        temp[this.name] = "";
                        a.push({name: this.name, value: ""});
                    }
                }
            });
            return a;
        };
        //开设账号
        form.on('submit(component-form-element)', function(){
            // data.field.content = layedit.getContent(index);
            var formObject={};
            var formArray=$("#myform").ghostsf_serialize();
            $.each(formArray,function(i,item){
                formObject[item.name]=item.value;
            })
            var checkbox =[];
            $("input[name=placeType]:checked").each(function(index,item){
                checkbox.push(item.value)
            });
            formObject["placeType"]=checkbox.toString();
            console.log(JSON.stringify(formObject))
            UpDateAccount(formObject);
            return false;
        });

        //头工具栏事件
        table.on('toolbar(LAY-user-manage)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add':
                    initUpdate();
                    break;
                case 'delete':
                    var data = checkStatus.data;
                    if (data.length > 0) {
                        //var id = new Array(); //声明数组
                        for (var i in data) {
                            var a = data[i].id;//得到复选框的值
                            postDelete(a);
                        }
                    } else {
                        layer.msg("至少选择一个进行删除");
                    }
                    break;
                case 'export':
                    layer.msg("导出");
                    break;
            }
        });

        //点击每行右工具栏“操作”里面按钮效果
        table.on('tool(LAY-user-manage)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                upData(data);
            } else if (obj.event === 'view') {
                initUpdate1(data);
            }else if (obj.event==='superior'){
                initUpdateSuperior();
            }else if(obj.event==='belongTo'){
                initUpdateBelongTo(data.agent_id);
            }else if (obj.event === 'del') {
                layer.confirm('删除以后数据将不能恢复，确定删除吗？', function(index) {
                    postDelete(data.id);
                });
            }else  if (obj.event === 'shebei'){
                openSheBei(data.id);
            }else if(obj.event==='zengzhi'){
                openZengZhi(data.id);
            }else if (obj.event==='listen'){
                // alert(obj.data.id)
                parent.layui.index.openTabsPage("base/link/@/dataShow/dataShow.jhtml?name="+obj.data.name+"&id="+obj.data.id, obj.data.name);
                //window.location.href="base/link/@/dataShow/dataShow.jhtml"
            }
        });
        //表单回显，赋值
        var title2="编辑账号信息";
        //ajax提交删除内容\
        window.postDelete = function (id) {
            $.ajax({
                url:delete_url,
                type: "POST",
                data: {
                    "pid": id
                },
                success: function (ret) {
                    if (ret == null) {
                        layer.msg("删除失败", {
                            icon: 5
                        });
                    } else {
                        layer.msg("删除成功", {
                            icon: 6
                        });
                        layer.closeAll();
                        table.reload('listReload');
                    }
                    return ret;
                }
            })
        };

        //开设账户ajax
        window.UpDateAccount = function (data) {
            var formData=new FormData();
            formData.append("data",JSON.stringify(data));
            $.ajax({
                url: saveUser_url,
                type: "POST",
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                    if (data.code == 0) {
                        layer.closeAll();
                        layer.msg(data.msg, {time: 600, icon: 1}, function () {
                            table.reload('listReload');
                        });
                        location.replace(location.href);
                    } else {
                        layer.msg(data.msg, {icon: 6});
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    var estr = "Page:" + window.location.pathname + ",Function:postUpdate()";
                    layer.open({
                        title: "错误信息",
                        type: 2,
                         content: "base/error.jhtml?info=" + estr,
                        btn: ['关闭'] //可以无限个按钮
                    });
                }
            });
        };
    });

</script>
<script>
    function show() {
        layer.tips("左边么么哒", "#"+id+"", {
            tips: [4, "#4794ec"]
        });
    }
</script>
</body>
</html>
